package com.example.demo.mapper;

import com.example.demo.bean.ShoppingCart;
import com.example.demo.bean.view.ShoppingCartView;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("ShoppingCartMapper")
public interface ShoppingCartMapper {
    //插入购物车的一个单项
    @Insert("insert into shoppingCart(shoppingCartNum, buyerNum, goodsNum, numOfGoods, belong) " +
            "value(#{shoppingCartNum}, #{buyerNum}, #{goodsNum}, #{numOfGoods}, #{belong})")
    public boolean insertShoppingCart(String shoppingCartNum, String buyerNum, String goodsNum, int numOfGoods, String belong);

    //删除一个购物车单项，通过用户账户与个人购物车编号锁定
    @Delete("delete from shoppingCart " +
            "where shoppingCartNum = #{shoppingCartNum}")
    public boolean deleteShoppingCart(String shoppingCartNum);

    //修改购物车内商品数量
    @Update("update shoppingCart " +
            "set numOfGoods = #{numOfGoods} " +
            "where shoppingCartNum = #{shoppingCartNum}")
    public boolean updateShoppingCart(String shoppingCartNum, int numOfGoods);

    //查找所有购物车数据
    @Select("select * from shoppingCart")
    public List<ShoppingCart> findAllShoppingCart();

    @Select("SELECT  shoppingCart.goodsNum, goods.sellerNum, shoppingCart.buyerNum, " +
            "        shoppingCart.shoppingCartNum, goods.goodsIntroduction, goods.goodsName, " +
            "        goods.price, goods.goodsType, goods.goodsNum, user.member ,goods.imag " +
            "FROM User, shoppingCart, goods " +
            "WHERE user.userNum = shoppingCart.buyerNum and goods.goodsNum = shoppingCart.goodsNum ")
    public List<ShoppingCartView> findAllShoppingCartView();
    //查看某一个人的购物车
    @Select("SELECT  shoppingCart.goodsNum, goods.sellerNum, shoppingCart.buyerNum, " +
            "        shoppingCart.shoppingCartNum, goods.goodsIntroduction, goods.goodsName, " +
            "        goods.price, goods.goodsType, goods.goodsNum, user.member ,goods.imag " +
            "FROM User, shoppingCart, goods " +
            "WHERE shoppingCart.buyerNum = #{buyerNum} and user.userNum = shoppingCart.buyerNum and goods.goodsNum = shoppingCart.goodsNum ")
    public List<ShoppingCartView> findShoppingCartByBuyerNum(String buyerNum);

}
